package cn.tedu.boot21.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BmiController {

    @RequestMapping("/bmi")
    @ResponseBody
    public String bmi(float height, float weight) {
        System.out.println("height = " + height + ", weight = " + weight);
        //BMI
        float bmi = weight / (height * height);
        //根据BMI判断
        /*
            接收用户输入的身高和体重,将判断结果输出
            过轻：低于18.5
            正常：18.5 ~ 22.9
            偏胖：23 ~ 24.9
            肥胖：25 ~ 29.9
            重度肥胖：高于30
            极度肥胖：高于40

            BMI 指数测试 BMI = 体重 (kg) / 身高² (m)
         */
        if (bmi < 18.5) {
            return "过轻";
        }
        if (bmi <= 22.9) {
            return "正常";
        }
        if (bmi <= 24.9) {
            return "偏胖";
        }
        if (bmi <= 29.9) {
            return "肥胖";
        }
        if (bmi <= 40) {
            return "重度肥胖";
        }
        return "极度肥胖";
    }
}

